package com.zsz.Util;

import org.apache.ibatis.session.SqlSession;
import org.apache.ibatis.session.SqlSessionFactory;
import org.apache.ibatis.session.SqlSessionFactoryBuilder;

import javax.annotation.Resources;
import java.io.InputStream;

public class MybatisUtils {
    private static SqlSessionFactory factory=null;
    static {
        String config="/mybatis.xml";//需要和你的项目中的文件名一样
        InputStream in=Resources.class.getResourceAsStream(config);
        SqlSessionFactoryBuilder builder=new SqlSessionFactoryBuilder();
        factory = builder.build(in);



    }


    //获取SqlSession的方法
    public static SqlSession getSqlSession(){
        SqlSession sqlSession=null;
        if (factory!=null){
            sqlSession=factory.openSession();//非自动提交事务

        }
        return sqlSession;
    }





}
